Discover static function variable, include the articles, news, trends, analysis and practical advice about static function variable on alibabacloud.com
The 1.static global variable is only initialized once, preventing it from being referenced in other file units;2.static Local variables are initialized only once, the next time based on the last result value;The 3.static function has only one copy
Original blog, reprint please indicate the source--Zhou Xuewei http://www.cnblogs.com/zxouxuewei/Static is used in two ways: static in process-oriented programming and static in object-oriented programming. The former applies to ordinary variables
1, can local variables and global variable duplicate?
A: Yes, the local will screen the overall situation. To use a global variable, you need to use the "::"
Local variables can have the same name as global variables, and when referenced within a
the difference between static variable and ordinary variable
The description of the global variable (external variable) before being labeled static constitutes a static global variable. The global variable itself is the static storage mode, static
I. Static variables static variables are roughly divided into three usage types
1. It is used in local variables to become static local variables. Static local variables have two usages: Memory Function and global survival.
2. It is used for
Static function (modifier function, local variable, global variable)In the C language, the literal meaning of static can easily lead us astray. In fact, it has three functions.(1) first introduce the first and most important one: hiding.When we
concept: static variables are scoped to a file , the program starts with space allocated, the space is freed at the end, the default is initialized to 0, and its value can be changed when used. static variables or static functions only the code in
Static variables exist only in the scope of the function, static variables only live in the stack, the next time you call this function, the value of the variable will be preserved
Static variables exist only within the scope of the function, and
1. Constants: Also known as final variables, can only be assigned once in the entire programfinal int num = 1215;num = 1216; //error, can only be assigned once2. Class member variable: A variable that is not defined in a method is a member variable,
Static Keywords of C ++
The static function of C ++ has two usage methods: static in process-oriented programming and static in object-oriented programming. The former applies to common variables and functions, and does not involve classes. The
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.